﻿
var wsUrl = "http://" + GetHostIp() + "/weeklybpm/webservice/Public.asmx/";
var iFCO = null;
try{ iFCO = window.parent.frames(0).document.theFCO;}
catch(e){}

function GetHostIp()
{
   //获取当前主机的IP地址;
   var loc;
   var url;
   var servername;
   var endat;
   url=window.location.href;
   loc=url.search("/");
   loc=loc+2; 
   url=url.substring(loc);
   endat=url.search("/");
   servername=url.substring(0,endat);
   return servername;
}


function GetUserFullName(user_code,user_name)
{
    $.ajaxSetup({async: false });
    user_code = window.parent.frames(0).document.theFCO.getVarValue(user_code);
    $.post(wsUrl + "GetUserFullName",{"user_code":user_code}, function(data)
    {
        iFCO.setVarValue(user_name, data.text);
    }); 
}

function GetApplyDate(strTime)
{
    var time = iFCO.getVarValue(strTime);
    if(time=="")
    {
        GetServerTime(strTime);
    }
}

function GetServerTime(strTime)
{
    $.ajaxSetup({async: false });
    $.post(wsUrl + "GetServerTime",function(data)
    {
        iFCO.setVarValue(strTime, data.text);
    });    
}

function GetGuid()
{

    if(iFCO.getVarValue("guid")=="" || iFCO.getVarValue("guid")==null)
    {
        $.ajaxSetup({async: false });
        $.post(wsUrl + "GetGuid",function(data)
        {
            iFCO.setVarValue("guid", data.text);
        }); 
    }
}

function GetRootDepName(cell_dptName,cell_user_ult_code)
{
    $.ajaxSetup({async: false });
    var user_ult_code = iFCO.getVarValue(cell_user_ult_code);
    $.post(wsUrl + "GetRootDepName",{"strUserUltCode":user_ult_code},function(data)
    {
        iFCO.setVarValue(cell_dptName, data.text);
    }); 
}

function GetManagerByDptName(cell_dptName,cell_dptManager_user_ult_code,cell_dptManager_user_name)
{
    $.ajaxSetup({async: false });
    var dptName = window.parent.frames(0).document.theFCO.getVarValue(cell_dptName);
    $.post(wsUrl + "GetManagerByDptName",{"strDptName":escape(dptName)},function(data)
    {
        var user=data.text.split('*');
        window.parent.frames(0).document.theFCO.setVarValue(cell_dptManager_user_ult_code, user[0]);
        window.parent.frames(0).document.theFCO.setVarValue(cell_dptManager_user_name, user[1]);
    }); 
}

function GetFirstDptManager(cell_dptName,cell_dptManager_user_ult_code,cell_dptManager_user_name)
{
    $.ajaxSetup({async: false });
    var dptName = window.parent.frames(0).document.theFCO.getVarValue(cell_dptName);
    $.post(wsUrl + "GetFirstDptManager",{"strDptName":escape(dptName)},function(data)
    {
        var user=data.text.split('*');
        window.parent.frames(0).document.theFCO.setVarValue(cell_dptManager_user_ult_code, user[0]);
        window.parent.frames(0).document.theFCO.setVarValue(cell_dptManager_user_name, user[1]);
    });
}

function ShenpiList()
{	
    try
    {
        guid=window.parent.frames(0).document.theFCO.getVarValue("guid");
        var ShenpiList = window.document.getElementById("FrameShenpList");
        var strHtml = "<IFRAME id='FrameShenpList' width='100%' SRC='/bpm_ex/ShenpiList.aspx?guid="+guid+"' frameborder='no'  marginwidth='0' marginheight='0' scrolling='no'  allowtransparency='true' onload='this.height=this.contentWindow.document.body.scrollHeight'></IFRAME>";  
        ShenpiList.innerHTML = strHtml;    
    }
    catch(exception)
    {
    }
}


function ShenpiResult(yes,no,ret)
{
    yes = iFCO.getVarValue(yes);
    no = iFCO.getVarValue(no);
    ret = iFCO.getVarValue(ret);
    
    var result = "";
    if(yes=="1")
    {
        result = "同意";
    }
    else if(no=="1")
    {
        result = "拒绝";
    }
    else if(ret == "1")
    {
        result = "退回";
    }
    
    iFCO.setVarValue("审批结果",result)
}


function GetApplyStepInfo()
{
    GetGuid();
    GetUserFullName("User Name","申请人姓名");
    GetApplyDate("申请时间");
    GetRootDepName("申请部门","User Name");
    ShenpiList();
    GetManagerByDptName("申请部门","部门领导人ID","部门领导人姓名");
}

function GetShenpiStepInfo()
{
    GetUserFullName("User Name","审批人姓名");
    GetServerTime("审批时间");
    ShenpiList();
    ClearShenpi();
}

//清空审批意见
function ClearShenpi()
{
    iFCO.setVarValue("审批意见","");
    iFCO.setVarValue("审批同意","0");
    iFCO.setVarValue("审批拒绝","0");
    iFCO.setVarValue("审批退回","0");
} 

function GetCookieData()
{
    var data;
    var IDStr="Data";//获取数据
    var iFCO=window.parent.frames[0].document.theFCO;
    var allcookies = document.cookie;//获取浏览器cookies
    if(allcookies.indexOf(IDStr)>=0)//浏览器cookies是否包含供应商ID
    {
        var str=document.cookie.split(";")//分解所有cookies
        for(var i=0;i<str.length;i++)
        {
            if(str[i].indexOf(IDStr)>=0)
            {
                data=str[i].split("=")[1];
                return data;
            }
        }        
    }
}

/******************************************************************************************/
/*选人页面OpenChooseUser参数说明  
  参数说明：usercode：人员账号对应的电子表格变量
            Username：人员姓名对应的电子表格变量
            retModel：用户人员账号返回值格式跟人员姓名返回值格式，单行或是多行，中间用*分隔 1：单个电子表格变量，2：多行变量 如：1*2
            type:    Type=1 部门、 Type=2 工作组、Content=部门名/工作组名
            Model:   选人模式，单选或是多选   1：单选，2：多选
*/
function OpenChooseUser(usercode,username,retModel,type,Model,Content)
{
   var retval ="";
   var showy=(screen.availHeight - 460)/2;    
   var showx=(screen.availWidth - 700)/2;
   var strContent = Content;
   retModel = retModel.split('*');
   var strUrl="/bpm/UnitManage/ChooseUser.aspx?type="+type+"&Content=" + strContent +"&model="+Model;   
   retval=window.showModalDialog(strUrl, "", "dialogWidth:700px; dialogHeight:460px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
 
   try
   {      
        setValue(retModel[0],retval[0],usercode);
        setValue(retModel[1],retval[1],username);
   }
   catch(e)
   {
   }   
}
function setValue(retModel, retValue, position) {
    if (retModel == '1') {
        iFCO.setVarValue(position, retValue.replace(/~/g, "，"));
    }
    else {
        iFCO.setVarValuesT(position, "");
        iFCO.setVarValuesT(position, retValue.replace(/~/g, "<+>"));
    }
}

//function setValue(retModel,retValue,position)
//{
//    if(retModel=='1')
//    {
//        iFCO.setVarValue(position, retValue.replace(/~/g,"，"));
//    }
//    else
//    {
//        iFCO.setVarValuesT(position, retValue.replace(/~/g,"<+>"));
//    }
//}
/******************************************************************************************/


function OpenChooseDpt(cell_dpt)
{
    var showy=(screen.availHeight - 460)/2;    
    var showx=(screen.availWidth - 700)/2;
    var strUrl="/bpm_ex/ChooseDpt.aspx";   
    retval=window.showModalDialog(strUrl, "", "dialogWidth:240px; dialogHeight:700px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
    if(retval=="" || retval==null || retval==undefined)
    {
        iFCO.setVarValue(cell_dpt,"");
    }
    else
    {
        iFCO.setVarValue(cell_dpt,retval);
    }
}

/******************************************************************************************/
//保存业务数据
function SaveData()
{
    var iFCO = window.parent.frames(0).document.theFCO;
    var tableName=iFCO.getVarValue("tableName");
    var strField=iFCO.getVarValue("strField");
    var strFieldType=iFCO.getVarValue("strFieldType");
    var strData=iFCO.getVarValue("strData");
    var ret = true;
    $.ajaxSetup({async: false });
    
    $.post(wsUrl + "SaveData",{"tableName":tableName,"strField":strField, "strFieldType":strFieldType,"strData":escape(strData)},function(data)
    {
        if(data.text=="False")
        {
            ret = false;
        }
        else
        {
            ret = true;
        }
    }); 
    return ret;
}
/******************************************************************************************/


/******************************************************************************************/
//审批步骤提交验证
function Valid()
{
    var tongyi = window.parent.frames(0).document.theFCO.getVarValue("审批同意");
    var tuihui = window.parent.frames(0).document.theFCO.getVarValue("审批退回");
    var jujue = window.parent.frames(0).document.theFCO.getVarValue("审批拒绝");
    var yijian = window.parent.frames(0).document.theFCO.getVarValue("审批意见");
    
    if(yijian=="")
    {
        if(tongyi=="1")
        {
            return true;
        }
        else
        {
            if(tuihui=="1" || jujue=="1")
            {
                alert("请输入意见");
                return false;
            }
            else
            {
                alert("请选择审批状态");
                return false;
            }
        }
    }
    else
    {
        if(tongyi=="1" || tuihui=="1" || jujue=="1")
        {
            return true;
        }
        else
        {
            alert("请选择审批状态");
            return false;
        }
    }
}
/******************************************************************************************/



/******************************************************************************************/  
/*打开模态对话框*/
/*参数说明
    src:需要打开的页面地址
    width:模态对话框宽度
    height:模态对话框高度
    showScroll:是否显示滚动条
*/
function openWin(src, width, height, showScroll)
{   
    window.showModalDialog (src,"","location:No;status:No;help:No;dialogWidth:"+width+";dialogHeight:"+height+";scroll:"+showScroll+";");   
}   
/******************************************************************************************/

/******************************************************************************************/
/*打开模态对话框*/
/*参数说明
    strUrl:需要嵌入的页面地址
    formFrameId:表单控件的ID
    iFrameId:嵌入iframe的ID
*/
function SetIframePage(strUrl,formFrameId,iFrameId)
{	
    try
    {
        var varFormFrameId = window.document.getElementById(formFrameId);
        var strHtml = "<IFRAME id='" + iFrameId + "' width='100%' height='100%' SRC='" + strUrl + "' frameborder='no'  marginwidth='0' marginheight='0' scrolling='no'  allowtransparency='true' ></IFRAME>";  
        varFormFrameId.innerHTML = strHtml;    
    }
    catch(exception)
    {
    }
}
/******************************************************************************************/

/******************************************************************************************/
/*打开模态对话框*/
/*参数说明
    obj:要验证的文本框对象
*/
function fillNumOnly(obj) 
{
    str = obj.value;
    if (trim(str) == "")
        return;
    if (/[^0-9]/g.test(str)) 
    {
        obj.value = str.substr(0, str.length - 1);
    }
}
/******************************************************************************************/


function trim(str){ //删除左右两端的空格
　　     return str.replace(/(^\s*)|(\s*$)/g, "");
　　 }
　　 function ltrim(str){ //删除左边的空格
　　     return str.replace(/(^\s*)/g,"");
　　 }
　　 function rtrim(str){ //删除右边的空格
　　     return str.replace(/(\s*$)/g,"");
　　 }


function GetLeads(cell_dptNames,cell_Lead_ult_code)
{
    $.ajaxSetup({async: false });
    var dptName = window.parent.frames(0).document.theFCO.getVarValue(cell_dptNames);
    iFCO.setVarValuesT(cell_Lead_ult_code,"");
    $.post(wsUrl + "GetLeads",{"strDptNames":escape(dptName)},function(data)
    {
        window.parent.frames(0).document.theFCO.setVarValuesT(cell_Lead_ult_code, data.text);
    });
}

function GetGeneralLead(cell_dptName,cell_Lead_ult_code)
{
    $.ajaxSetup({async: false });
    var dptName = window.parent.frames(0).document.theFCO.getVarValue(cell_dptName);
    $.post(wsUrl + "GetGeneralLead",{"dpt_name":escape(dptName)},function(data)
    {
        window.parent.frames(0).document.theFCO.setVarValue(cell_Lead_ult_code, data.text);
    });
}



function GetMarketLead(cell_strDptName,cell_user_ult_code)
{
    $.ajaxSetup({async: false });
    var dptName = window.parent.frames(0).document.theFCO.getVarValue(cell_strDptName);
    $.post(wsUrl + "GetMarketLead",{"strDptName":escape(dptName)},function(data)
    {
        window.parent.frames(0).document.theFCO.setVarValue(cell_user_ult_code, data.text);
    });
}




function GetCurrentDpt(cell_strDpt)
{
    $.ajaxSetup({async: false });
    var strUserUltCode = window.parent.frames(0).document.theFCO.getVarValue("User Name");
    $.post(wsUrl + "GetCurrentDpt",{"strUserUltCode":strUserUltCode},function(data)
    {
        iFCO.setVarValue(cell_strDpt, data.text);
    });    
}





//JScript 文件

//SureGridView的Row单击Function
function RowClick(row, PriValue)
{
    //alert(event.srcElement.tagName);
    //alert(event.srcElement.innerHTML);
    if(event.srcElement.tagName=="A")
    {
        switch(event.srcElement.innerHTML)
        {
            case "编辑":
            case "Edit":
                showModalDialog();
                return false;
                break;
            case "删除":
            case "Delete":
                return confirm("确定删除信息？");
                break;
            default:
        }
    }
    return true;
}

//SureGridView的EditRow单击Function
function EditRowClick(row)
{
    if(event.srcElement.tagName=="A")
    {
        switch(event.srcElement.innerHTML)
        {
            case "删除":
            case "Delete":
                if(confirm("确定删除信息？"))
                {
                    row.style.display = "none";
                    document.getElementById(row.id + "_hidRowDisplay").value = "none";
                    //alert(document.getElementById(row.id + "_hidRowDisplay").value);
                    var i,j;
                    for(i=0;i<row.cells.length;i++)
                    {
                        for(j=0;j<row.cells[i].childNodes.length;j++)
                        {
                            if(row.cells[i].childNodes[j].type=="text")
                            {
                                row.cells[i].childNodes[j].style.display = "none";
                            }
                        }
                    }
                }
                return false;
                break;
            default:
        }
    }
    return true;
}

//SureGridView的AddRow单击Function
function AddRow(TableID)
{
    var objTable = document.getElementById(TableID);
    var objRows = objTable.rows;
    var w = 0;
    var objPreRow;
    //0为表头
    for(w=1;w<objRows.length;w++)
    {
        if(objRows[objRows.length - 1].style.display!="none")
        {
            alert("无法继续增加信息！");
            return false;
        }
        else
        {
            if(objRows[w].style.display=="none")
            {
                objPreRow = objRows[w];
                break;
            }
            else
            {
            }
        }
    }
    objPreRow.style.display = "block";
    document.getElementById(objPreRow.id + "_hidRowDisplay").value = "block";
    var i,j;
    for(i=0;i<objPreRow.cells.length;i++)
    {
        for(j=0;j<objPreRow.cells[i].childNodes.length;j++)
        {
            if(objPreRow.cells[i].childNodes[j].type=="text")
            {
                objPreRow.cells[i].childNodes[j].style.display = "block";
            }
        }
    }
    
    return false;
}

//SureMergeTextBox的onfocus
function SmtxFocus(obj, url, width, height)
{
    try
    {
	    url = url + "?arg=" + GetArg(obj);
    }
    catch(ex)
    {}
    var strObj = showModalDialog(url, null, "dialogWidth=" + width + "px;dialogHeight=" + height + "px");
    if(strObj!=null&&strObj!="")
    {
        //值
        document.getElementById(obj.id.replace("LiuxdText", "LiuxdValue")).value = strObj.split('^')[0];
        //文本
        obj.value = strObj.split('^')[1];
        //alert(document.getElementById(obj.id.replace("MergeLiuxdText", "MergeLiuxdValue")).value);
        
        //
        
        try
        {
            DoSetListValue(obj ,strObj.split('^')[2]);
        }
        catch(ex)
        {}
    }
    obj.blur();
}

//SureGridView的行中控件值变化
function RowChange(obj, objID)
{
    if(document.getElementById(obj.id.replace(objID, "hidRowStatus")).value=="normal")
    {
        document.getElementById(obj.id.replace(objID, "hidRowStatus")).value = "update";
    }
    //alert(document.getElementById(obj.id.replace(objID, "hidRowStatus")).value);
}


